package com.autumn.annotations.aop.aspect;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import java.util.Arrays;

/**
 * ClassName: CalcAspect
 *
 * @Description:
 * @Author: wangqiuyang
 * @Date: 2022/1/26 2:08 下午
 * History:
 * <author>          <time>          <version>          <desc>
 * wangqiuyang    2022/1/26 2:08 下午   @Version 1.0        描述
 */
@Aspect
public class CalcAspect {

    @Pointcut("execution(public int com.autumn.annotations.aop.logic.Cacl.div(int,int))")
    public void pointCut(){}

    @Before(value = "pointCut()")
    public void start(JoinPoint joinpoint) {
        String name = joinpoint.getSignature().getName();
        Object[] args = joinpoint.getArgs();
        System.out.println("@Before : ----" + name + " ... 开始执行 ... 参数为" + Arrays.asList(args));
    }

    @After("pointCut()")
    public void end (JoinPoint joinpoint) {
        String name = joinpoint.getSignature().getName();
        System.out.println("@After : ----" + name +  " ... 结束执行 ...");
    }

    @AfterReturning(value = "pointCut()" , returning = "result")
    public void logReturn(int result) {
        System.out.println("@AfterReturning : ---- 执行结果 {"+result+"} ...");
    }

    @AfterThrowing(value = "pointCut()" , throwing = "e")
    public void logException(Exception e) {
        System.out.println("@AfterThrowing : ----  执行异常 {"+e+"} ...");
    }

}
